package com.school.express.service.impl;

import com.school.express.domain.Express;
import com.school.express.domain.Logistics;
import com.school.express.domain.Sign;
import com.school.express.mapper.ExpressMapper;
import com.school.express.mapper.LogisticsMapper;
import com.school.express.mapper.SignMapper;
import com.school.express.service.SignService;
import zhibi.common.support.base.service.BaseServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import zhibi.common.support.exception.MessageException;

import java.util.Date;

/**
* The class create by 执笔 on generate.
*/
@Service
@Transactional
public class SignServiceImpl extends BaseServiceImpl<Sign> implements SignService{

    @Autowired
    public SignServiceImpl(SignMapper mapper) {
        super(mapper);
        this.signMapper = mapper;
    }
    private SignMapper signMapper;
    @Autowired
    private ExpressMapper expressMapper;
    @Autowired
    private LogisticsMapper logisticsMapper;

    @Override
    public void sign(Sign sign) {
        Express express =expressMapper.selectByPrimaryKey(sign.getExpressId());
        if(null == express){
            throw new MessageException("该快递不存在");
        }
        express.setStatus(3);
        expressMapper.updateByPrimaryKeySelective(express);
        sign.setAddtime(new Date());
        signMapper.insertSelective(sign);
        Logistics logistics = new Logistics();
        logistics.setExpressId(express.getId());
        logistics.setAddtime(new Date());
        logistics.setRemark("快递签收，签收人:"+sign.getRemark());
        logisticsMapper.insertSelective(logistics);
    }
}